<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        console.log(only([1, 2, 2, 2, 2, 5, 56, 67, 7, 7, 7]));

        //核心算法：遍历旧数组，然后拿着旧数组的元素去查询新数组，若新数组中没有则添加
        function only(arr) {
            var arr2 = [];
            if (arr instanceof Array) {
                for (var i = 0; i < arr.length; i++) {
                    if (arr2.indexOf(arr[i]) == -1) {
                        arr2.push(arr[i]);
                    }
                }
                return arr2;
            } else {
                return '格式';
            }
        }
    </script>
</head>

<body>

</body>

</html>